{% spaceless %}
{% load extra_filters %}
{% load timezone_filters %}

<?xml version="1.0" encoding="UTF-8"?>
<kml xmlns="http://earth.google.com/kml/2.2">
<Document>
  <Style id="lapstyle0">
    <LineStyle>
      <color>ffff0000</color>
      <width>4</width>
    </LineStyle>
  </Style>
  <Style id="lapstyle1">
    <LineStyle>
      <color>ffffff00</color>
      <width>4</width>
    </LineStyle>
  </Style>
  <Style id="lapstyle2">
    <LineStyle>
      <color>ff00ff00</color>
      <width>4</width>
    </LineStyle>
  </Style>
  <Style id="lapstyle3">
    <LineStyle>
      <color>ff006633</color>
      <width>4</width>
    </LineStyle>
  </Style>
{% for lap in activity.lap_set %}
<Placemark>
  <visibility>1</visibility>
  <name>CycleTrack Lap {{forloop.counter}}</name>
  <description>
    <![CDATA[
<table><tr>
    <td>Name: {{ activity.name }}</td><td></td>
</tr>
<tr>
  <td>Start Time:</td><td>{{ lap.starttime|localtime:user.get_profile.timezone }}</td>
</tr>
<tr>
  <td>End Time:</td><td>{{ lap.endtime|localtime:user.get_profile.timezone }}</td>
</tr>
<tr>
  <td>Distance:</td><td>{{ lap.total_meters|meters_to_prefered_distance:user.get_profile.use_imperial }}</td>
</tr>
<tr>
  <td>Rolling Time:</td><td>{{ lap.total_rolling_time_seconds|seconds_to_human_readable }}</td>
</tr>
<tr>
  <td>Total Time:</td><td>{{ lap.total_time_seconds|seconds_to_human_readable }}</td>
</tr>
<tr>
  <td>Speed:</td>
  <td>Avg: {{ lap.average_speed|kph_to_prefered_speed:user.get_profile.use_imperial }},Max: {{ lap.maximum_speed|kph_to_prefered_speed:user.get_profile.use_imperial }}</td>
</tr>
<tr>
  <td>Heart Rate:</td><td>Avg: {{ lap.average_bpm }}, Max: {{ lap.maximum_bpm }} BPM</td>
</tr>
<tr>
  <td>Cadence:</td><td>Avg: {{ lap.average_cadence }}, Max: {{ lap.maximum_cadence }} RPM</td>
</tr>
<tr>
  <td>Calories:</td><td>{{ lap.calories|floatformat:"-2" }}</td>
</tr>
</table>
<a href="http://cycletracks.appspot.com/{{ activity.get_absolute_url }}">View at CycleTracks</a>
]]>
</description>
  <styleUrl>#lapstyle{{forloop.counter0}}</styleUrl>
  <LineString>
      <coordinates>{{ lap.to_kml }}</coordinates>
      <extrude>1</extrude>
      <tessellate>1</tessellate>
  </LineString>
  </Placemark>
{% endfor %}
</Document>
{% endspaceless %}
</kml>
